import { minioApi } from './common'

export * from './admin'
export * from './aigc-admin'
export * from './common'
export * from './customer'
export * from './online-lab'

// 针对minio文件地址的自定义下载
export const fetchDownload = async (url: string, fileName: string): Promise<any> => {
  const res = await fetch(url)
  if (!res.ok) {
    throw new Error('下载文件失败')
  }
  const blob = await res.blob()
  const href = URL.createObjectURL(blob)
  const a = document.createElement('a')
  a.style.display = 'none'
  a.href = href
  a.download = fileName
  a.click()
  URL.revokeObjectURL(href)
}

export const isMinioFileExist = async (url: string) => {
  try {
    const { data } = await minioApi.checkFile({ fileName: url })
    return data
  } catch (error) {
    console.error(error)
    return false
  }
}
